#include <iostream>
#include <stack>
using namespace std;
bool check(string s)
{
    stack<char> stack;
    for(int i  = 0; i< s.size(); i++)
    {
        if(stack.empty())
            stack.push(s[i]);
        else
        {
            if((stack.top() =='(' && s[i]==')')||(stack.top() =='[' && s[i]==']')||(stack.top() =='{' && s[i]=='}') )
                stack.pop();
            else
                stack.push(s[i]);
        }
    }
    return stack.empty();
}    
int main()
{
    int n;
    cin>>n;
    string s;
    for(int i = 0; i<n; i++)
    {
        cin>>s;
        if(check(s))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}